﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.ServiceModel.Activities;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Activities.Description;
using System.Activities;
namespace LibraryReservation
{
    class Program
    {
        static void Main(string[] args)
        {
            string adr = ConfigurationManager.AppSettings["Address"];
            Console.WriteLine(ConfigurationManager.AppSettings["Branch Name"]);
            WorkflowService service = new WorkflowService
            {
                Name = "LibraryReservation",
                Body = new ProcessRequest(),
                Endpoints ={
                    new Endpoint{
                        ServiceContractName = "ILibraryReservation",
                        AddressUri = new Uri("http://localhost:"+adr+"/LibraryReservation"),
                        Binding = new BasicHttpBinding(),
                    }
                }
            };

            WorkflowServiceHost wsh = new WorkflowServiceHost(service);
            wsh.Open();

            Console.WriteLine("Waiting for requests, press ENTER to send a request.");
            Console.ReadLine();
            IDictionary<string, object> input = new Dictionary<string, object>{
                {"Title","Gone with the Wind"},
                {"Author","Margaret Mitchell"},
                {"ISBN","9781416548898"}
            };
            IDictionary<string, object> output = WorkflowInvoker.Invoke(new SendRequest(), input);
            ReservationResponse resp = output["Response"] as ReservationResponse;
            Console.WriteLine("Response received from the {0} branch",resp.Provider.BranchName);

            Console.WriteLine();
            Console.WriteLine("Press ENTER to exit");
            Console.ReadLine();

            wsh.Close(); 
        }
    }
}
